<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/WEB-INF/templates/default.xhtml">
        <ui:define name="title">
            <h:outputText value="#{i18n['main.label.title']}" />
        </ui:define>

        <ui:define name="content">
            <h:form id="messagesForm">
                <p:dataTable id="messageTable" var="message" value="#{mainBean.messages}" paginator="true" rows="15"
                             paginatorTemplate="#{i18n['data.label.count']}: #{mainBean.messages.size()}   {RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" 
                             rowsPerPageTemplate="5,15,30" rowStyleClass="#{empty message.jmsId ? 'important' : null}">

                    <f:facet name="header">  
                        <h:outputText value="#{i18n['label.table.panel.title']}" />
                    </f:facet>

                    <p:column headerText="#{i18n['message.jmsId']}" sortBy="#{message.jmsId}" filterBy="#{message.jmsId}">
                        <h:outputText value="#{message.jmsId}" />
                    </p:column>

                    <p:column headerText="#{i18n['message.type']}" sortBy="#{i18n[message.type]}" filterBy="#{message.type}" filterOptions="#{mainBean.messageTypeFilterOptions}" filterMatchMode="exact">
                        <h:outputText value="#{i18n[message.type]}" />
                    </p:column>

                    <p:column headerText="#{i18n['message.destinationType']}" sortBy="#{i18n[message.destinationType]}"  filterBy="#{message.destinationType}" filterOptions="#{mainBean.destinationTypeFilterOptions}" filterMatchMode="exact">
                        <h:outputText value="#{i18n[message.destinationType]}" />
                    </p:column>

                    <p:column headerText="#{i18n['message.destinationName']}" sortBy="#{message.destinationName}" filterBy="#{message.destinationName}">
                        <h:outputText value="#{message.destinationName}" />
                    </p:column>

                    <p:column headerText="#{i18n['message.timestamp']}" sortBy="#{message.timestamp.time}">
                        <h:outputText value="#{message.timestamp.time}">
                            <f:convertDateTime locale="#{localeBean.locale}" type="both" pattern="#{i18n['application.pattern.timestamp']}" />
                        </h:outputText>
                    </p:column>

                    <p:column headerText="#{i18n['data.label.actions']}" styleClass="center-align">
                        <p:commandButton id="selectButton" update=":messagesForm:display" oncomplete="messageDialog.show();" icon="ui-icon-search" title="#{i18n['button.show']}">
                            <f:setPropertyActionListener value="#{message}" target="#{mainBean.selectedMessage}" />
                        </p:commandButton>
                    </p:column>
                </p:dataTable>

                <p:dialog header="#{i18n['label.message.details.title']}" widgetVar="messageDialog" resizable="false">

                    <p:panelGrid id="display" styleClass="main-dialog">
                        <p:row>  
                            <p:column><h:outputText value="#{i18n['message.jmsId']}:" /></p:column>
                            <p:column><h:outputText value="#{mainBean.selectedMessage.jmsId}" styleClass="detail-value" /></p:column>
                        </p:row>

                        <p:row>  
                            <p:column><h:outputText value="#{i18n['message.type']}:" /></p:column>
                            <p:column><h:outputText value="#{i18n[mainBean.selectedMessage.type]}" styleClass="detail-value" /></p:column>
                        </p:row>

                        <p:row>  
                            <p:column><h:outputText value="#{i18n['message.destinationType']}:" /></p:column>
                            <p:column><h:outputText value="#{i18n[mainBean.selectedMessage.destinationType]}" styleClass="detail-value" /></p:column>
                        </p:row>

                        <p:row>  
                            <p:column><h:outputText value="#{i18n['message.destinationName']}:" /></p:column>
                            <p:column><h:outputText value="#{mainBean.selectedMessage.destinationName}" styleClass="detail-value" /></p:column>
                        </p:row>

                        <p:row>  
                            <p:column><h:outputText value="#{i18n['message.destinationJmsType']}:" /></p:column>
                            <p:column><h:outputText value="#{mainBean.selectedMessage.destinationJmsType}" styleClass="detail-value" /></p:column>
                        </p:row>

                        <p:row>  
                            <p:column><h:outputText value="#{i18n['message.deliveryMode']}:" /></p:column>
                            <p:column><h:outputText value="#{i18n[mainBean.selectedMessage.deliveryMode]}" styleClass="detail-value" /></p:column>
                        </p:row>

                        <p:row>  
                            <p:column><h:outputText value="#{i18n['message.transactionType']}:" /></p:column>
                            <p:column><h:outputText value="#{i18n[mainBean.selectedMessage.transactionType]}" styleClass="detail-value" /></p:column>
                        </p:row>

                        <p:row>  
                            <p:column><h:outputText value="#{i18n['message.timestamp']}:" /></p:column>
                            <p:column>
                                <h:outputText value="#{mainBean.selectedMessage.timestamp.time}" styleClass="detail-value">
                                    <f:convertDateTime locale="#{localeBean.locale}" type="both" pattern="#{i18n['application.pattern.timestamp']}" />
                                </h:outputText>
                            </p:column>
                        </p:row>

                        <p:row>  
                            <p:column colspan="2">
                                <p:fieldset legend="#{i18n['message.headers']}" toggleable="true" collapsed="true">
                                    <p:inputTextarea value="#{mainBean.selectedMessage.headers}" readonly="true" cols="80" rows="10" autoResize="false"/>
                                </p:fieldset>
                            </p:column>
                        </p:row>

                        <p:row>  
                            <p:column colspan="2">
                                <p:fieldset legend="#{i18n['message.properties']}" toggleable="true" collapsed="true">
                                    <p:inputTextarea value="#{mainBean.selectedMessage.properties}" readonly="true" cols="80" rows="10" autoResize="false"/>
                                </p:fieldset>
                            </p:column>
                        </p:row>

                        <p:row>  
                            <p:column colspan="2">
                                <p:fieldset legend="#{i18n['message.body']}" toggleable="true">
                                    <p:inputTextarea value="#{mainBean.selectedMessage.body}" readonly="true" cols="80" rows="10" autoResize="false"/>
                                </p:fieldset>
                            </p:column>
                        </p:row>
                    </p:panelGrid>
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>
</html>